package ma.jeetconsulting.pocs.domain;

import java.util.Set;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;


@Entity
@Table(name ="t_dependency")
@DiscriminatorValue("Dependecy")
public class Dependency implements RuleEngineObject{

	private static final long serialVersionUID = -3559956460951921789L;

	private Long id;
	private String groupId;
	private String artifactId;
	private String version;
	private Set<Dependency> dependencies;
	
	public Dependency(String groupId, String artifactId, String version) {
		this.groupId = groupId;
		this.artifactId = artifactId;
		this.version = version;
	}
	
	public Dependency() {
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	

	public String getGroupId() {
		return groupId;
	}

	public void setGroupId(String groupId) {
		this.groupId = groupId;
	}

	public String getArtifactId() {
		return artifactId;
	}

	public void setArtifactId(String artifactId) {
		this.artifactId = artifactId;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	@ManyToMany
	@JoinTable(name="DEP_DEPENDENCIES")
	public Set<Dependency> getDependencies() {
		return dependencies;
	}

	public void setDependencies(Set<Dependency> dependencies) {
		this.dependencies = dependencies;
	}
	
	public boolean hasSameGroupAndArtifact(Dependency dependency) {
		return groupId.equals(dependency.getGroupId()) && artifactId.equals(dependency.getArtifactId());
	}

}
